// import $ from 'jquery';
import * as signalR from '@aspnet/signalr'
import myUtils from '@/utils/myUtils'
import GWVideo from '../components/videoComponent.vue'
import timeSelect from '@/components/app-time-select/index.vue'

// import exportEquip from '../components/equipSelects/equipSelect.vue'
import myTree from "@/components/tree";

export default {
    components: {
        GWVideo,
        timeSelect,

        // exportEquip,
        myTree
    },
    data() {
        return {
            curveType: {
                name: "实时",
                func: null
            },
            equipObject: {},
            nodeObject: {},
            alarmList: [],
            signalrConnection: null,
            exportSignalrConnection: null,
            signalrConnectionEquip: null,
            defaultTime: ["00:00:00", "23:59:59"],
            pickerMinDate: "",
            pickerOptions: {
                disabledDate(time) {
                    let hmTime =
                        myUtils.getCurrentDate(0, "-").substring(0, 10) +
                        " 24:00:00";
                    let date = new Date(hmTime);
                    let thatDay = date.getTime();
                    return time.getTime() >= thatDay;
                }
            },
            chartHistoryTime: [],
            equipNumber: 0, // 设备总数
            tabNavNumber: 1,

            equipChartNm: "", // 曲线图-设备名称

            tabHeaderSetShow: false,

            // 左侧设备列表
            equipList: [],
            searchEquipSide: [], // 提供搜索的数组
            rightWord: "",

            // 搜索输入框内容
            searchEquipSideCon: "",
            mainSearchCon: "",

            // 选中的设备名\设备状态
            groupName: "",
            equipConNm: "",
            equipConState: "",
            selectedEquip: "",

            // 表格数据
            equipYcAndYxNo: "",
            tableDataYc: [],
            tableDataYx: [],
            tableDataSet: [],

            pagesize: 15,
            pageIndex: 0,

            inputStyle: false, // 搜索框样式-左侧列表
            inputStyleMain: false, // 搜索框样式---main

            isShow: 0,
            equipChildActiveId: 0,

            // 选择的设备信息
            distinguish: true,
            equipNo: "",

            // 当前设备
            nowEquipStaNo: 1,
            nowEquipNo: "",

            tabNavType: 1, // [遥测量:1],[遥信量:2],[设置:3]

            // 只执行一次判断
            ycShow: true,
            yxShow: false,
            equipSetShow: false,
            addEquipShow: false,

            loading: true,

            // 分页-左侧设备列表
            pageNoLeft: 1, // 初始化第一页

            // 分页-右侧设备列表
            pageSizeRight: 9999,
            pageNoRight: 1, // 初始化第一页
            totalRight: 1,

            curveShow: false,
            curveShowHistory: false,

            curveShowCurve: false,
            curveShowCurveHistory: false,

            // 请求历史曲线的参数
            dataHistory: [],
            historyData: [],
            hisChart: null,
            hisChartRealTime: null,

            searchWordLeft: "", // 左侧搜索

            // 实时值参数
            equipDataYc: [],
            equipDataYx: [],
            ycData: [],
            yxData: [],

            // 测点数量
            stationNumber: {
                setNum: 0,
                ycNum: 0,
                yxNum: 0
            },

            // 历史曲线数组
            equipHistory: [],
            loadingHistory: false,

            equipNoList: [],

            searchResult: false,
            nodeLoad: false,

            // 模糊查询变量
            searchVariable: "",
            sendSearchData: [],
            IntervalTime: 1000,
            equipListItem: "", // 查找设备列表中设备
            currentEquipNo: "",
            setTimeoutStatus: true,

            // 实时视频
            videoShow: false,
            videoValue: [],
            tableHeight: 776,

            // 定时器
            clearTimeoutVariable: null,
            firstEquipFlag: true, // 首次开启数据推送
            equipHistoryList: 0,

            // app
            equipConMainEquipListDisplayNone: true,
            appStartTimeValue: "",
            appEndTimeValue: "",

            exportDialog: false,
            exportType: 3,
            typeList: [
                {
                    name: "全部",
                    value: 3
                },
                {
                    name: "正常",
                    value: 1
                },
                {
                    name: "告警",
                    value: 2
                },
                {
                    name: "离线",
                    value: 0
                }
            ],
            exportLoading: false,
            exportCurveLoading: false,
            showExportCurve: false,
            showExportTypeSelect: false,
            isMerge: false,
            exportTypeOption: [
                {
                    label: "equipList.exportType[0]",
                    value: false
                },
                {
                    label: "equipList.exportType[1]",
                    value: true
                }
            ],
            exportCurveData: {},
            noData: "",
            haveData: true,
            showBottom: true,
            htmlHeight: "",
            appHeight: "",
            appFrameHeight: "",
            getAppFrameHeight: "",
            setPagination: {
                pageSize: 20,
                pageNo: 1,
                total: 0
            },
            staNo: ""
        };
    },
    computed: {
        returnStatus() {
            return status => {
                let className = "CommunicationOK";
                switch (parseInt(status)) {
                    case 0:
                        className = "NoCommunication";
                        break;
                    case 1:
                        className = "CommunicationOK";
                        break;
                    case 2:
                        className = "HaveAlarm";
                        break;
                    case 3:
                        className = "HaveSetParm";
                        break;
                    case 4:
                        className = "initial";
                        break;
                    case 5:
                        className = "CheFang";
                        break;
                    case 6:
                        className = "BackUp";
                        break;
                    default:
                        className = "CommunicationOK";
                        break;
                }
                return className;
            };
        }
    },
    updated() {
        let box = document.getElementById("elTable");
        if (box) {
            this.tableHeight = box.offsetHeight;
        }
    },
    mounted() {
        let box = document.getElementById("elTable");
        window.onresize = function windowResize() {
            box = document.getElementById("elTable");
            if (box) {
                this.tableHeight = box.offsetHeight;
            }
        };
        const { systemName } = this.$route.query;
        if (systemName) {
            this.systemName = systemName;
        }
        this.equipSide();

        let that = this;
        window.onmessage = function(e) {
            if (e.data.exportYes) {
                that.exportCurveLoading = false;
            }
        };

        this.curveType.func = this.onSplineChartRealTime;
    },

    beforeRouteUpdate() {
        this.clearTimer();
    },

    // 销毁前
    beforeDestroy() {
        this.clearTimer();

        if (this.signalrConnection) {
            this.signalrConnection.stop();
        }
        if (this.signalrConnectionEquip) {
            this.signalrConnectionEquip.stop();
        }
        this.onCloseVideo();
    },

    // 销毁完成
    destroyed() {
        this.clearTimer();

        if (this.timeChart) {
            clearInterval(this.timeChart);
        }
        if (this.signalrConnection) {
            this.signalrConnection.stop();
        }
        if (this.signalrConnectionEquip) {
            this.signalrConnectionEquip.stop();
        }
        this.onCloseVideo();
    },

    // 离开路由之前执行的函数
    beforeRouteLeave(to, from, next) {
        this.clearTimer();
        if (this.signalrConnection) {
            this.signalrConnection.stop();
        }
        if (this.signalrConnectionEquip) {
            this.signalrConnectionEquip.stop();
        }
        next();
    },

    methods: {
        switchCurve(type) {
            if (type === "1") {
                this.curveType.name = "历史";
                this.curveType.func = this.onSplineChartHistory;
            } else {
                this.curveType.name = "实时";
                this.curveType.func = this.onSplineChartRealTime;
            }
        },

        deviceSearchChange() {
            if (this.searchEquipSideCon == "") {
                this.onSearchSide();
                this.haveData = true;
            }
        },
        showExportCurveDialog() {
            this.showExportCurve = true;
        },
        confirmExportCurve() {
            this.exportCurveLoading = true;
            delete this.exportCurveData.equipsList;
            this.exportCurveData.isMerge = this.isMerge;
            let exportData = JSON.stringify(this.exportCurveData);
            window.parent.postMessage({
                openCurveLink: true,
                exportData: exportData
            });
            this.showExportTypeSelect = false;
        },
        setGroupStatus(key, type) {
            if (type) {
                this.nodeObject[key].alarmCounts =
                    this.nodeObject[key].alarmCounts + 1;
                if (this.nodeObject[key].alarmCounts > 0) {
                    this.nodeObject[key].status = 2;
                }
            } else {
                this.nodeObject[key].alarmCounts =
                    this.nodeObject[key].alarmCounts - 1;
                if (this.nodeObject[key].alarmCounts == 0) {
                    this.nodeObject[key].status = 1;
                }
            }
            if (this.nodeObject[key].parent) {
                this.setGroupStatus(this.nodeObject[key].parent.key, type);
            }
        },

        formateList(list) {
            let arr = [];
            for (const item of list) {
                let dataItem = {};
                dataItem.count = item.count;
                dataItem.title = item.groupName;
                dataItem.key = item.groupId;
                dataItem.isGroup = true;
                dataItem.children = [];
                dataItem.status = 1;
                if (item.equipLists.length > 0) {
                    dataItem.children = [
                        ...dataItem.children,
                        ...item.equipLists.map(equip => {
                            return {
                                count: 0,
                                title: equip.equipName,
                                equipState: equip.equipState,
                                key: equip.equipNo,
                                staNo: equip.staNo,
                                status: equip.equipState
                            };
                        })
                    ];
                }
                if (item.children.length > 0) {
                    dataItem.children = [
                        ...dataItem.children,
                        ...this.formateList(item.children)
                    ];
                }

                arr.push(dataItem);
            }
            return arr;
        },

        formateEquips(list, parent) {
            for (const item of list) {
                if (!item.children) {
                    this.equipObject[item.key] = {};
                    this.equipObject[item.key] = item;
                    this.equipObject[item.key].parent = parent;
                    if (item.equipState == 2) {
                        this.alarmList.push({
                            equipNo: item.key,
                            status: 2
                        });
                    }
                }
                if (item.children) {
                    this.nodeObject[item.key] = {};
                    this.nodeObject[item.key] = item;
                    this.nodeObject[item.key].alarmCounts = 0;
                    this.nodeObject[item.key].status = 1;
                    if (parent) {
                        this.nodeObject[item.key].parent = parent;
                    }
                    this.formateEquips(item.children, item);
                }
            }
        },

        exportCurve(data) {
            if (data) {
                if (!data.beginTime) {
                    this.$message.warning(this.$t("publics.warnings[3]"));
                    return;
                }
                if (!data.endTime) {
                    this.$message.warning(this.$t("publics.warnings[4]"));
                    return;
                }
                if (new Date(data.beginTime) > new Date(data.endTime)) {
                    this.$message.warning(this.$t("publics.warnings[0]"));
                    return;
                }
                if (
                    parseInt(
                        Math.abs(
                            new Date(data.beginTime).getTime() -
                                new Date(data.endTime).getTime()
                        ) /
                            1000 /
                            60 /
                            60 /
                            24
                    ) > 90
                ) {
                    this.$message.warning(this.$t("publics.warnings[1]"));
                    return;
                }

                if (data.equipsList && data.equipsList.length > 0) {
                    if (data.exportEquips && data.exportEquips.length == 0) {
                        this.$message.warning(this.$t("equipList.warnings[1]"));
                        return;
                    }
                } else {
                    this.$message.warning(this.$t("equipList.warnings[0]"));
                    return;
                }
                this.exportCurveData = JSON.parse(JSON.stringify(data));
                this.showExportTypeSelect = true;
            } else {
                this.showExportCurve = false;
                this.exportCurveLoading = false;
            }
        },
        exportEquip() {
            this.exportDialog = true;
        },

        confirmExport() {
            let that = this;
            this.exportLoading = true;
            this.$api
                .exportAbnormalRecord({
                    deviceStatus: this.exportType == 3 ? -1 : this.exportType
                })
                .then(res => {
                    this.exportLoading = false;
                    if (res.status === 200) {
                        let url = window.URL.createObjectURL(
                            new Blob([res.data])
                        );
                        let link = document.createElement("a");
                        link.style.display = "none";
                        link.href = url;
                        let date = new Date();
                        let dateStr = `${date.getFullYear()}-${date.getMonth() +
                            1}-${date.getDate()}`;
                        let excelName = "";
                        switch (that.exportType) {
                            case 0:
                                excelName = that.$t("equipList.excelName[1]");
                                break; // 离线
                            case 1:
                                excelName = that.$t("equipList.excelName[3]");
                                break; // 正常
                            case 2:
                                excelName = that.$t("equipList.excelName[0]");
                                break; // 告警
                            case 3:
                                excelName = that.$t("equipList.excelName[4]");
                                break; // 全部
                            default:
                                break;
                        }
                        link.setAttribute(
                            "download",
                            dateStr + "-" + excelName + ".xlsx"
                        );
                        document.body.appendChild(link);
                        link.click();
                        that.exportDialog = false;
                    } else {
                        this.$message.error(this.$t("publics.tips.exportFail"));
                    }
                })
                .catch(err => {
                    this.exportLoading = false;
                    let reader = new FileReader();
                    reader.readAsText(err.data, "utf-8");
                    reader.onload = function(e) {
                        let content = JSON.parse(reader.result);
                        that.$message.error(content.message);
                    };
                });
        },

        // 关闭视频
        onCloseVideo() {
            this.videoShow = false;
        },

        // 测点监控视频
        onYcYxVideo(item) {
            this.videoShow = true;
            this.videoValue = [];
            if (!window.localStorage.ac_session) {
                // h5流媒体视频
                this.myUtils.streamLogin();
            }
            if (item.relatedVideo === "") {
                this.$message({
                    message: this.$t("equipList.mesVideo[0]"),
                    type: "warning"
                });
                return;
            }
            this.$api
                .getEquipNumCatVideoId(String(item.relatedVideo))
                .then(rt => {
                    if (rt.data.code === 200 && rt.data.data) {
                        this.videoValue.push(rt.data.data[0].equipNum);
                        this.videoValue.push(rt.data.data[0].path);
                        this.videoValue.push(rt.data.data[0].channelNum);
                        this.videoValue.push(rt.data.data[0].id);

                        if (!window.localStorage.ac_session) {
                            this.$message({
                                message: this.$t("equipList.mesVideo[1]"),
                                type: "warning"
                            });
                        }
                    } else {
                        this.$message.warning(this.$t("equipList.mesVideo[0]"));
                    }
                });
        },

        // 设备数据推送
        connectHubEquipState(equipNo) {
            this.signalrConnectionEquip = null;
            this.signalrConnectionEquip = new signalR.HubConnectionBuilder()
                .withUrl(this.$api.getSignalrHttp() + "/monitor", {})
                .build();
            let that = this;

            // 开始连接this.signalrConnectionr
            that.signalrConnectionEquip
                .start()
                .then(() => {
                    that.signalrConnectionEquip.invoke("OnConnect", equipNo);
                })
                .catch(function(ex) {
                    console.log("connectHub 连接失败" + ex);
                });
            console.log("开始设备的推送----", equipNo);
            that.signalrConnectionEquip.off("EquipDataChanged");
            that.signalrConnectionEquip.on("EquipDataChanged", res => {
                let data = JSON.parse(res);

                for (const item of data) {
                    if (item.equipNo == this.nowEquipNo) {
                        this.equipConState = item.equipState;
                    }
                    this.equipObject[item.equipNo].equipState = item.equipState;
                    if (
                        item.equipState == 2 &&
                        this.equipObject[item.equipNo].status != 2
                    ) {
                        if (this.equipObject[item.equipNo].parent) {
                            let key = this.equipObject[item.equipNo].parent.key;
                            this.setGroupStatus(key, true); // 加一
                        }
                    } else if (
                        this.equipObject[item.equipNo].status == 2 &&
                        item.equipState != 2
                    ) {
                        if (this.equipObject[item.equipNo].parent) {
                            let key = this.equipObject[item.equipNo].parent.key;
                            this.setGroupStatus(key, false); // 减一
                        }
                    }

                    this.setStatus(
                        this.equipList,
                        item.equipNo,
                        item.equipState
                    );
                }
                that.$forceUpdate();
            });
        },

        setStatus(list, equipNo, equipStatus) {
            for (const item of list) {
                const { key, status } = item;
                if (
                    parseInt(key) == parseInt(equipNo) &&
                    equipStatus != status
                ) {
                    item.status = equipStatus;
                    break;
                }
                if (item.children) {
                    this.setStatus(item.children, equipNo, equipStatus);
                }
            }
        },

        // 测点数据推送
        connectHub(equipNo) {
            let that = this;
            this.signalrConnection = null;
            this.signalrConnection = new signalR.HubConnectionBuilder()
                .withUrl(this.$api.getSignalrHttp() + "/monitor", {})
                .build();

            that.signalrConnection
                .start()
                .then(() => {
                    that.signalrConnection.invoke("OnConnect", equipNo);
                })
                .catch(function(ex) {
                    console.log("connectHub 连接失败" + ex);
                });

            // 当设备的推送断开时重连
            if (this.signalrConnectionEquip == null) {
                console.log("重新连接设备的数据推送---");
                that.connectHubEquipState(equipNo);
            }

            // 开始连接this.signalrConnectionr
            that.signalrConnection.off("YcpDataChanged");
            that.signalrConnection.on("YcpDataChanged", res => {
                let data = JSON.parse(res);
                let tableDataYc = that.tableDataYc;
                if (data != null && data.length > 0 && tableDataYc.length > 0) {
                    tableDataYc.forEach((itemI, i) => {
                        data.forEach((itemJ, j) => {
                            if (
                                itemJ != null &&
                                itemI.ycNo === itemJ.ycNo &&
                                itemI.equipNo === itemJ.equipNo
                            ) {
                                itemI.value = itemJ.value;
                                try {
                                    // 设备离线或者实时值不是number类型都为离线置灰色equipState
                                    if (!that.equipConState) {
                                        itemI.isAlarm = "noComm";
                                        itemI.equipState = "noComm";
                                        itemI.stateText = this.$t(
                                            "equipList.state[2]"
                                        );
                                    } else {
                                        itemI.isAlarm = itemJ.state
                                            ? "alarm"
                                            : "normal";
                                        itemI.equipState = itemJ.state
                                            ? "alarm"
                                            : "normal";
                                        itemI.stateText = itemJ.state
                                            ? this.$t("equipList.state[1]")
                                            : this.$t("equipList.state[0]");
                                    }
                                } catch (e) {
                                    console.log("e--------", e);
                                }
                            }
                        });
                    });
                    this.tableDataYc = JSON.parse(JSON.stringify(tableDataYc));
                    that.$forceUpdate();
                }
            });

            that.signalrConnection.off("YxpDataChanged");
            that.signalrConnection.on("YxpDataChanged", res => {
                let data = JSON.parse(res);
                let tableDataYx = that.tableDataYx;
                if (data != null && data.length > 0 && tableDataYx.length > 0) {
                    tableDataYx.forEach((itemI, i) => {
                        data.forEach((itemJ, j) => {
                            if (
                                itemJ != null &&
                                itemI.yxNo == itemJ.yxNo &&
                                itemI.equipNo == itemJ.equipNo
                            ) {
                                try {
                                    itemI.value = itemJ.value;
                                    if (!that.equipConState) {
                                        itemI.equipState = "noComm";

                                        // itemI.value = this.$t('equipList.state[2]');
                                    } else {
                                        itemI.equipState = itemJ.state
                                            ? "alarm"
                                            : "normal";

                                        // itemI.value = itemJ.state ? this.$t(
                                        //     'equipList.state[1]') : this.$t(
                                        //     'equipList.state[0]')
                                    }
                                } catch (e) {
                                    console.log(e);
                                }
                            }
                        });
                    });
                    this.tableDataYx = JSON.parse(JSON.stringify(tableDataYx));
                }
                that.$forceUpdate();
            });

            that.signalrConnection.onclose(async () => {
                that.signalrConnection.stop();
            });
        },

        // 右侧---页码大小改变时触发事件
        handleSizeChangeRight(pageSize) {
            this.$refs.pagination.internalCurrentPage = 1;
            this.pageSizeRight = pageSize;
            this.pageNoRight = 1;
            this.equipYcAndYxAndSet(this.nowEquipStaNo, this.nowEquipNo);
        },

        // 右侧---当前页码改变时触发
        handleCurrentChangeRight(pageNo) {
            this.pageNoRight = pageNo;
            this.equipYcAndYxAndSet(this.nowEquipStaNo, this.nowEquipNo);
        },

        // 获取左侧设备列表
        equipSide() {
            let data = {
                pageNo: this.pageNoLeft,
                pageSize: 40,
                SearchName: this.searchWordLeft,
                systemName: this.systemName
            };
            this.nodeLoad = true;
            let equipList = [];
            this.$api
                .getEquipLists(data)
                .then(rt => {
                    this.nodeLoad = false;
                    this.loading = false;

                    // 搜索请求结果
                    if (rt.data.data.equipList == "") {
                        this.equipList = [];
                        this.searchResult = false;
                        this.equipNumber = 0;
                        return;
                    }
                    if (rt.data.code === 200) {
                        this.equipList = [];
                        this.searchResult = true;

                        if (data.SearchName.length > 0) {
                            this.equipNoList = rt.data.data.other;
                        } else {
                            this.equipNoList = rt.data.data.equipList;
                        }

                        equipList = rt.data.data.groups;

                        this.searchEquipSide = equipList; // 搜索数组
                        // 设备总数
                        if (rt.data.data.equipList.length > 0) {
                            let obj = rt.data.data.equipList.filter(item => {
                                if (item !== 0) {
                                    return item;
                                }
                                return 0;
                            });
                            this.equipNumber = obj.length;
                        } else {
                            this.equipNumber = 0;
                        }

                        this.equipList = this.formateList(equipList);

                        this.formateEquips(this.equipList);
                        for (const alarmItem of this.alarmList) {
                            if (this.equipObject[alarmItem.equipNo].parent) {
                                let key = this.equipObject[alarmItem.equipNo]
                                    .parent.key;
                                this.setGroupStatus(key, true);
                            }
                        }

                        // 首次开启
                        if (
                            this.equipNoList.length > 0 &&
                            this.firstEquipFlag
                        ) {
                            this.firstEquipFlag = false;
                            try {
                                if (this.signalrConnection) {
                                    this.signalrConnection.stop();
                                }
                            } catch (e) {
                                console.log(e);
                            }
                            if (this.clearTimeoutVariable) {
                                clearTimeout(this.clearTimeoutVariable);
                            }
                            this.clearTimeoutVariable = setTimeout(() => {
                                if (this.equipNoList[0]) {
                                    this.connectHubEquipState(
                                        this.equipNoList[0]
                                    );
                                }
                            }, 500);
                        }

                        this.$forceUpdate();
                    }
                })
                .catch(err => {
                    this.loading = false;
                    this.nodeLoad = false;
                    console.log("err---", err);
                });
        },

        findEquip(equiplist) {
            equiplist.forEach(item => {
                if (
                    item.equipLists &&
                    item.equipLists.length > 0 &&
                    !this.finded
                ) {
                    item.equipLists.forEach(itemJ => {
                        if (itemJ.equipNo !== 0) {
                            this.equipListItem = itemJ.equipNo;
                            this.finded = true;
                        }
                    });
                }

                if (!this.finded) {
                    if (item.children.length > 0) {
                        this.findEquip(item.children);
                    }
                }
            });
        },

        getEquipNo(list) {
            if (list.length > 0) {
                for (let i = 0; i < list.length; i++) {
                    if (list[i] != 0) {
                        this.currentEquipNo = list[i];
                        break;
                    }
                }
            }
        },

        // 获取当前设备遥测/遥信/设置---列表
        equipYcAndYxAndSet(staNo, equipNo) {
            if (equipNo == "") {
                this.$message.warning(
                    this.$t("equipList.timeUi.pleaseEquipment")
                );
                return;
            }

            this.equipNo = equipNo;
            this.staNo = staNo;

            //	this.tabNavType【1：遥测、2：遥信、3：设置】
            this.loading = true;
            let data = {
                staN: staNo,
                equipNo: equipNo,
                pageNo: this.pageNoRight,
                pageSize: this.pageSizeRight,
                searchName: this.rightWord
            };
            if (this.tabNavType === 1) {
                this.$api.getEquipListYcs(data).then(rt => {
                    this.loading = false;
                    if (rt.data.code === 200) {
                        this.totalRight = rt.data.data.count;
                        if (rt.data.data.count === 0) {
                            this.tableDataYc = [];
                            // setTimeout(() => {
                            //     this.loading = false;
                            // }, 2000);
                            return;
                        }
                        this.equipDataYc = rt.data.data.list;
                        this.tableDataYc = JSON.parse(
                            JSON.stringify(this.equipDataYc)
                        );
                        let ycData = {
                            equipNo: equipNo,
                            ycYxNos: rt.data.data.listNos,
                            value: 0
                        };
                        this.ycData = ycData;
                        this.getEquipRealTimeData(0);
                    }
                }).catch(err => {
                    console.log(err);
                    this.loading = false;
                })
            } else if (this.tabNavType === 2) {
                this.$api.getEquipListYxs(data).then(rt => {
                      this.loading = false;
                    if (rt.data.code === 200) {
                        this.totalRight = rt.data.data.count;
                        if (rt.data.data.count === 0) {
                            this.tableDataYx = [];
                        }
                        this.equipDataYx = rt.data.data.list;
                        this.tableDataYx = JSON.parse(
                            JSON.stringify(this.equipDataYx)
                        );
                        let yxData = {
                            equipNo: equipNo,
                            ycYxNos: rt.data.data.listNos
                        };
                        this.yxData = yxData;
                        this.getEquipRealTimeData(1);
                    }
                }).catch(err => {
                    console.log(err);
                    this.loading = false;
                })
            } else if (this.tabNavType === 3) {
                data.pageNo = 1;
                data.pageSize = 9999;
                this.$api.getEquipControlTable(data).then(rt => {
                    this.loading = false;
                    if (rt.data.code === 200) {
                        this.tableDataSet = rt.data.data.list;
                        this.totalSet = rt.data.data.count;
                        this.totalRight = rt.data.data.count;
                        this.setPagination.total = rt.data.data.count;
                        if (rt.data.data.count === 0) {
                            this.tableDataSet = [];
                            return;
                        }
                    }
                }).catch(err => {
                    console.log(err);
                    this.loading = false;
                })
            }
        },

        loadmore() {
            if (this.setPagination.total == this.tableDataSet.length) {
                return;
            }
            this.setPagination.pageNo = this.setPagination.pageNo + 1;
            let data = {
                staN: this.staNo,
                equipNo: this.equipNo,
                pageNo: this.setPagination.pageNo,
                pageSize: this.setPagination.pageSize,
                searchName: this.rightWord
            };
            this.$api.getEquipControlTable(data).then(rt => {
                if (rt.data.code === 200) {
                    this.tableDataSet = [
                        ...this.tableDataSet,
                        ...rt.data.data.list
                    ];
                    this.setPagination.total = rt.data.data.count;

                    // this.totalRight = rt.data.data.count
                }
            });
        },

        // 获取当前设备的遥测遥信实时值
        getEquipRealTimeData(typeNo) {
            let equipConState = this.equipConState;

            // typeNo：0【遥测】、typeNo：1【遥信】、typeNo：2【设置】
            let equipDataYc = this.equipDataYc;
            let equipDataYx = this.equipDataYx;
            let equipYcState = [];
            if (typeNo == 0) {
                this.$api
                    .getYcpByEquipNo({
                        equipNo: this.ycData.equipNo,
                        pageNo: this.pageNoRight,
                        pageSize: this.pageSizeRight
                    })
                    .then(rt => {
                        if (rt.data.code === 200) {
                            equipYcState = rt.data.data.rows;
                            if (equipYcState && equipYcState.length > 0) {
                                equipYcState.forEach((item, i) => {
                                    for (let l in equipDataYc) {
                                        if (
                                            equipDataYc[l].mergeAlarmCount ==
                                            null
                                        ) {
                                            equipDataYc[l].mergeAlarmCount = "";
                                        }
                                        if (item.ycNo == equipDataYc[l].ycNo) {
                                            let unit = equipDataYc[l].unit;

                                            if (unit != null) {
                                                if (
                                                    unit.indexOf("[") !== -1 &&
                                                    unit.indexOf("]") !== -1
                                                ) {
                                                    unit = unit.split("]");
                                                    equipDataYc[l].unit =
                                                        unit[unit.length - 1];
                                                }
                                            }
                                            equipDataYc[l].value = item.value;

                                            // 设备离线测点必须离线、设备双机热备下的测点必须是双机热备状态
                                            if (!equipConState) {
                                                equipDataYc[l].isAlarm =
                                                    "noComm";
                                                equipDataYc[
                                                    l
                                                ].stateText = this.$t(
                                                    "equipList.state[2]"
                                                );
                                            } else if (equipConState === 6) {
                                                equipDataYc[l].isAlarm =
                                                    "ycyxBackUp";
                                            } else {
                                                equipDataYc[
                                                    l
                                                ].isAlarm = item.state
                                                    ? "alarm"
                                                    : "normal";
                                                equipDataYc[
                                                    l
                                                ].stateText = item.state
                                                    ? this.$t(
                                                          "equipList.state[1]"
                                                      )
                                                    : this.$t(
                                                          "equipList.state[0]"
                                                      );
                                            }
                                        }
                                    }
                                });
                                this.tableDataYc = [];
                                this.tableDataYc = equipDataYc;
                            } else {
                                this.tableDataYc = this.equipDataYc;
                            }
                        }
                    });
            } else if (typeNo === 1) {
                // 当前设备遥信实时值
                this.$api
                    .getYxpByEquipNo({
                        equipNo: this.yxData.equipNo,
                        pageNo: this.pageNoRight,
                        pageSize: this.pageSizeRight
                    })
                    .then(rt => {
                        if (rt.data.code === 200) {
                            if (
                                rt.data.data.list &&
                                rt.data.data.list.length > 0
                            ) {
                                rt.data.data.list.forEach(item => {
                                    equipDataYx.forEach(itemJ => {
                                        if (item.mergeAlarmCount == null) {
                                            item.mergeAlarmCount = "";
                                        }
                                        if (item.yxNo == itemJ.yxNo) {
                                            if (!equipConState) {
                                                itemJ.equipState = "noComm";
                                                itemJ.value = item.value;

                                                // itemJ.value = this.$t('equipList.state[2]');
                                            } else if (equipConState === 6) {
                                                itemJ.equipState = "ycyxBackUp";
                                            } else {
                                                itemJ.equipState = item.state
                                                    ? "alarm"
                                                    : "normal";
                                                itemJ.isAlarm = item.state
                                                    ? "alarm"
                                                    : "normal";
                                                itemJ.stateText = item.state
                                                    ? this.$t(
                                                          "equipList.state[1]"
                                                      )
                                                    : this.$t(
                                                          "equipList.state[0]"
                                                      );
                                                itemJ.value = item.state
                                                    ? itemJ.evt10
                                                    : itemJ.evt01;

                                                // itemJ.value = item.state ? this.$t(
                                                //     'equipList.state[1]') : this.$t(
                                                //     'equipList.state[0]');
                                            }
                                        }
                                    });
                                });
                                this.tableDataYx = [];
                                this.tableDataYx = JSON.parse(
                                    JSON.stringify(equipDataYx)
                                );
                            } else {
                                this.tableDataYx = JSON.parse(
                                    JSON.stringify(this.equipDataYx)
                                );
                            }
                        }
                    });
            }
        },

        // 曲线图-返回当前遥测遥信实时值
        getEquipCurve(no, initValue) {
            let equipCurve = [];
            let num = 0;

            // 遥测实时值
            if (this.tabNavNumber === 1) {
                equipCurve = this.tableDataYc;
                equipCurve.forEach((item, i) => {
                    if (no == item.ycNo) {
                        num = item.value;
                    }
                });
            } else if (this.tabNavNumber === 2) {
                // 遥信实时值【0、1】
                equipCurve = this.tableDataYx;
                equipCurve.forEach((item, i) => {
                    if (no === item.yxNo) {
                        num = item.equipState === "normal" ? 1 : 0;
                    }
                });
            }
            if (typeof num != "number") {
                num = null;
            }

            if (String(typeof num) === "object") {
                return initValue;
            }
            return num;
        },

        // 开启实时曲线显示
        onSplineChartRealTime(item, type) {
            if (item.isAlarm === "noComm" || item.equipState === "noComm") {
                this.$message({
                    message: this.$t("equipList.timeUi.curveValue"),
                    type: "warning"
                });
                return;
            }
            this.curveShowCurve = true;
            this.curveShow = true;

            setTimeout(() => {
                this.hisChartRealTime = this.$echart.init(
                    document.getElementById("containerE"),
                    "light"
                );
                this.splineChart(type === "C" ? "C" : "X", item);
            }, 80);
        },

        // 关闭实时曲线、历史曲线
        onCloseCurve() {
            this.equipHistory = [];
            if (this.timeChart) {
                clearInterval(this.timeChart);
            }
            if (this.getYcValues) {
                clearInterval(this.getYcValues);
            }
            this.curveShow = false;
            this.curveShowCurve = false;
            this.curveShowCurveHistory = false;
            this.curveShowHistory = false;
            this.addEquipShow = false;
            this.zoneAddDeviceShow = false;
        },

        // 实时曲线
        activeLastPointToolip(chart) {
            let points = chart.series[0].points;
            chart.tooltip.refresh(points[points.length - 1]);
        },

        randomData(data) {
            return {
                name: this.myUtils.getCurrentDate(false, "/"),
                value: [
                    this.myUtils.getCurrentDate(false, "/"),
                    Math.round(data)
                ]
            };
        },
        splineChart(type, item) {
            if (this.timeChart) {
                clearInterval(this.timeChart);
            }
            let equipNm = "";
            let no = 0;
            no = type === "C" ? item.ycNo : item.yxNo;

            let that = this;
            this.equipChartNm = equipNm;
            let realTimeValue = []; // 实时值
            let physicMax = []; // 上限值
            let physicMin = []; // 下限值
            let initValue = item.value;

            let minValue = type === "C" ? Math.ceil(item.valMin * 0.8) : 2;
            let maxValue = type === "C" ? Math.ceil(item.valMax * 1.08) : 0;

            let smooth = true; // 曲线还是折线
            let axisLine = {
                lineStyle: {
                    type: "solid",
                    color: "#9197a0", // 左边线的颜色
                    width: "1" // 坐标线的宽度
                }
            };

            // let axisLabel = {
            //     textStyle: {
            //         color: '#e6e6e6' // 坐标值得具体的颜色
            //     }
            // }

            let textColor = "#C7CBD6";
            let lineColor = "#343a4c";
            if (
                window.localStorage.getItem("theme") &&
                window.localStorage.getItem("theme") == "light"
            ) {
                textColor = "#595959";
                lineColor = "#e6e6e6";
            }

            function legendTitleRight(title) {
                return {
                    name: title,
                    textStyle: {
                        fontSize: 12,
                        color: textColor
                    }
                };
            }
            let legendData = [
                legendTitleRight(that.$t("equipList.titleHistory[0]"))
            ];
            let seriesList = [
                {
                    type: "line",
                    name: that.$t("equipList.titleHistory[0]"),
                    smooth,
                    lineStyle: {
                        color: {
                            type: "linear",
                            x: 0,
                            y: 0,
                            x2: 1,
                            y2: 0,
                            colorStops: [
                                {
                                    offset: 1,
                                    color: "#0174FF" // 0% 处的颜色
                                },
                                {
                                    offset: 0,
                                    color: "#2BCC8F" // 100% 处的颜色
                                }
                            ]
                        }
                    },
                    itemStyle: {
                        color: {
                            type: "linear",
                            x: 0,
                            y: 0,
                            x2: 1,
                            y2: 0,
                            colorStops: [
                                {
                                    offset: 1,
                                    color: "#0174FF" // 0% 处的颜色
                                },
                                {
                                    offset: 0,
                                    color: "#2BCC8F" // 100% 处的颜色
                                }
                            ]
                        }
                    },
                    showSymbol: true,
                    hoverAnimation: true,
                    data: this.randomData(that.getEquipCurve(no, initValue))
                }
            ];

            if (type === "C") {
                physicMax.push(this.randomData(item.valMax));
                physicMin.push(this.randomData(item.valMin));

                that.equipChartNm = item.ycNm;

                legendData = [
                    legendTitleRight(that.$t("equipList.titleHistory[0]")),
                    legendTitleRight(that.$t("equipList.titleHistory[1]")),
                    legendTitleRight(that.$t("equipList.titleHistory[2]"))
                ];

                seriesList.push(
                    {
                        name: that.$t("equipList.titleHistory[1]"),
                        type: "line",
                        smooth,
                        color: "rgba(242,36,51,0.6)",
                        style: {
                            color: "#d3d8e2"
                        },
                        showSymbol: false,
                        hoverAnimation: true,
                        data: physicMax,
                        itemStyle: {
                            normal: {
                                lineStyle: {
                                    width: 2,
                                    type: "dotted" // 'dotted'虚线 'solid'实线
                                }
                            }
                        }
                    },
                    {
                        name: that.$t("equipList.titleHistory[2]"),
                        type: "line",
                        smooth,
                        color: "rgba(245,187,54,0.6)",
                        style: {
                            color: "#d3d8e2"
                        },
                        showSymbol: false,
                        hoverAnimation: true,
                        data: physicMin,
                        itemStyle: {
                            normal: {
                                lineStyle: {
                                    width: 2,
                                    type: "dotted" // 'dotted'虚线 'solid'实线
                                }
                            }
                        }
                    }
                );
            } else {
                that.equipChartNm = item.yxNm;
            }
            this.hisChartRealTime.setOption({
                grid: {
                    left: "4%",
                    top: "10%",
                    right: "7%",
                    bottom: "7%",
                    containLabel: true
                },
                tooltip: {
                    trigger: "axis",
                    backgroundColor: "rgba(0,0,0,0.5)",
                    borderRadius: "0",
                    formatter: function(params) {
                        params = params[0];
                        return (
                            '<span style="color:#999">时间：' +
                            params.value[0] +
                            '</span><br/><span style="color:#999">当前值：</span>' +
                            '<span style="color:#3875ff">' +
                            params.value[1] +
                            "</span>"
                        );
                    },
                    axisPointer: {
                        animation: true
                    }
                },
                legend: {
                    show: true,
                    orient: "horizontal", // 'vertical'
                    x: "right",
                    y: "top",
                    left: "30",
                    top: "7",
                    data: legendData,
                    textStyle: {
                        color: "red"
                    }
                },
                xAxis: {
                    type: "time",
                    splitLine: {
                        show: false
                    },
                    labels: {
                        style: {
                            color: "#595959"
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: "rgba(240, 244, 255, 0.56)",
                            width: 1 // 这里是为了突出显示加上的
                        }
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            fontSize: 10,
                            color: textColor // 更改坐标轴文字颜色
                        }
                    },
                    splitNumber: 3
                },
                yAxis: {
                    type: "value",
                    boundaryGap: [0, "100%"],
                    min: minValue,
                    max: maxValue,
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: lineColor,
                            width: 1
                        }
                    },
                    axisLine: {
                        show: false
                    },
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: "rgba(150, 154, 165, 0.5)" // 更改坐标轴文字颜色
                        }
                    },
                    axisTick: {
                        show: false
                    }
                },

                series: seriesList,
                backgroundColor: "transparent"
            });

            if (type === "C") {
                function c() {
                    if (realTimeValue.length > 40) {
                        realTimeValue.shift();
                        physicMax.shift();
                        physicMin.shift();
                    }
                    realTimeValue.push(
                        that.randomData(that.getEquipCurve(no, initValue))
                    );
                    physicMax.push(that.randomData(item.valMax));
                    physicMin.push(that.randomData(item.valMin));

                    that.hisChartRealTime.setOption({
                        series: [
                            {
                                data: realTimeValue
                            },
                            {
                                data: physicMax
                            },
                            {
                                data: physicMin
                            }
                        ]
                    });
                    if (that.getEquipCurve(no, initValue) > item.valMax) {
                        that.hisChartRealTime.setOption({
                            yAxis: {
                                max: Math.ceil(
                                    that.getEquipCurve(no, initValue) * 1.08
                                )
                            }
                        });
                    }
                    if (that.getEquipCurve(no, initValue) < item.valMin) {
                        that.hisChartRealTime.setOption({
                            yAxis: {
                                min: Math.ceil(
                                    that.getEquipCurve(no, initValue) * 1
                                )
                            }
                        });
                    }
                }
                c();
                this.timeChart = setInterval(() => {
                    c();
                }, that.IntervalTime);
            } else {
                function x() {
                    if (realTimeValue.length > 40) {
                        realTimeValue.shift();
                    }
                    realTimeValue.push(
                        that.randomData(that.getEquipCurve(no, initValue))
                    );
                    that.hisChartRealTime.setOption({
                        series: [
                            {
                                data: realTimeValue
                            }
                        ]
                    });
                }
                x();
                this.timeChart = setInterval(() => {
                    x();
                }, that.IntervalTime);
            }
        },

        // 历史曲线---显示
        onSplineChartHistory(item, type) {
            this.chartHistoryTime = [];
            this.curveShowCurveHistory = true;
            let ycpNo = type === "C" ? item.ycNo : item.yxNo;

            // 显示时清空app端时间选择组件数据
            this.appStartTimeValue = "";
            this.appEndTimeValue = "";
            this.curveShowHistory = true;

            this.equipChartNm = item.ycNm;
            this.dataHistory = {
                type,
                beginTime: "",
                endTime: "",
                staNo: item.staN,
                equipNo: item.equipNo,
                ycpNo
            };
            this.chartHistoryTime.push(
                this.myUtils.getCurrentDate(1, "-") + " 00:00:00"
            );
            this.chartHistoryTime.push(
                this.myUtils.getCurrentDate(1, "-") + " 23:59:59"
            );
            this.dataHistory.beginTime =
                this.myUtils.getCurrentDate(1, "-") + " 00:00:00";
            this.dataHistory.endTime =
                this.myUtils.getCurrentDate(1, "-") + " 23:59:59";
            this.beginTime = this.myUtils.getCurrentDate(1, "-") + " 00:00:00";
            this.endTime = this.myUtils.getCurrentDate(1, "-") + " 23:59:59";
            setTimeout(() => {
                this.hisChart = this.$echart.init(
                    document.getElementById("historyData"),
                    "light"
                );
            }, 88);
        },

        // app时间选择
        appStartTime() {
            this.chartHistoryTime[0] = this.appStartTimeValue;
            this.beginTime = this.appStartTimeValue;
            this.dataHistory.beginTime = this.appStartTimeValue;
            if (this.chartHistoryTime.length === 2) {
                this.onInquire();
            }
        },

        appEndTime() {
            this.chartHistoryTime[1] = this.appEndTimeValue;
            this.endTime = this.appEndTimeValue;
            this.dataHistory.endTime = this.appEndTimeValue;
            if (this.chartHistoryTime[0]) {
                this.onInquire();
            }
        },

        // 历时曲线---确定时间---获取开始、结束时间戳
        checkTime() {
            if (this.chartHistoryTime == null) {
                this.dataHistory.beginTime = "";
                this.dataHistory.endTime = "";
                return;
            }
            this.beginTime = this.chartHistoryTime[0];
            this.endTime = this.chartHistoryTime[1];
            this.dataHistory.beginTime = this.chartHistoryTime[0];
            this.dataHistory.endTime = this.chartHistoryTime[1];
        },

        // 历史曲线---开始查询
        onInquire() {
            if (
                this.dataHistory.beginTime === "" ||
                this.dataHistory.endTime === ""
            ) {
                this.$message({
                    message: this.$t("equipList.timeUi.timeHorizon"),
                    type: "warning"
                });
                return;
            }
            let appBeginTime = this.dataHistory.beginTime
                .replace(/-/g, "")
                .replace(/:/g, "")
                .replace(/ /g, "");
            let appEndTime = this.dataHistory.endTime
                .replace(/-/g, "")
                .replace(/:/g, "")
                .replace(/ /g, "");
            if (appEndTime < appBeginTime) {
                this.$message({
                    message: this.$t("equipList.timeUi.timeRange"),
                    type: "warning"
                });
                return;
            }

            // 查询天数限制
            // let beginTime = this.dataHistory.beginTime.slice(0, 10)
            // let endTime = this.dataHistory.endTime.slice(0, 10)
            // if (this.myUtils.dateDiff(beginTime, endTime) > 7) {
            //     this.myUtils.messageType('warning', this.$t('equipList.timeUi.timeDays'));
            //     return;
            // }

            this.equipHistory = [];
            this.loadingHistory = true;
            this.equipHistoryList = 0;

            // let datasss = {
            //     beginTime: "2021-03-18 00:00:00",
            //     endTime: "2021-03-18 23:59:59",
            //     equipNo: 11144,
            //     staNo: 1,
            //     type: "X",
            //     ycpNo: 1
            // }

            this.$api
                .getEquipGetCurData(this.dataHistory)
                .then(rt => {
                    this.loadingHistory = false;

                    if (rt.data.code === 200) {
                        let equipHistory = rt.data.data.list;
                        if (
                            equipHistory.times == "" ||
                            equipHistory.values == ""
                        ) {
                            this.$message.error(
                                this.$t("equipList.timeUi.queryHistory")
                            );
                            this.equipHistory = [];
                            return;
                        }

                        this.equipHistory = equipHistory.values;

                        this.equipHistoryList = equipHistory.values.length;

                        let historyTime = equipHistory.times;
                        let historyValue = equipHistory.values;
                        let textColor = "#f4f4f4";
                        let lineColor = "#343a4c";
                        if (
                            window.localStorage.getItem("theme") &&
                            window.localStorage.getItem("theme") == "light"
                        ) {
                            textColor = "#595959";
                            lineColor = "#e6e6e6";
                        }

                        setTimeout(() => {
                            this.hisChart.setOption({
                                grid: {
                                    left: "15",
                                    top: "7%",
                                    right: "15",
                                    bottom: "14%",
                                    containLabel: true,
                                    color: "red"
                                },
                                tooltip: {
                                    style: {
                                        color: "red"
                                    }
                                },
                                xAxis: {
                                    type: "category",
                                    splitLine: {
                                        show: false,
                                        lineStyle: {
                                            // x网格线
                                            color: "red"
                                        }
                                    },
                                    axisLine: {
                                        lineStyle: {
                                            color: "rgba(240, 244, 255, 0.56)",
                                            width: 1 // 这里是为了突出显示加上的
                                        }
                                    },
                                    axisLabel: {
                                        margin: 12,
                                        textStyle: {
                                            color: textColor,
                                            fontSize: "12"
                                        },
                                        formatter: (val) => {
                                            return val.replace(' ','\n');
                                        }
                                    },
                                    labels: {
                                        style: {
                                            color: "#d3d8e2"
                                        }
                                    },
                                    style: {
                                        color: "#d3d8e2"
                                    },

                                    data: historyTime
                                },
                                yAxis: {
                                    gridLineColor: "#3b4357",
                                    gridLineWidth: 1,
                                    type: "value",
                                    axisLine: {
                                        show: false
                                    },
                                    axisTick: {
                                        show: false
                                    },
                                    axisLabel: {
                                        margin: 12,
                                        textStyle: {
                                            color: "rgba(150, 154, 165, 0.5)",
                                            fontSize: "13"
                                        }
                                    },
                                    style: {
                                        color: textColor,
                                        fontWeight: "bold",
                                        fontSize: "12px",
                                        fontFamily:
                                            "Trebuchet MS, Verdana, sans-serif"
                                    },

                                    title: {
                                        style: {
                                            color: textColor,
                                            fontWeight: "bold",
                                            fontSize: "12px",
                                            fontFamily:
                                                "Trebuchet MS, Verdana, sans-serif"
                                        }
                                    },
                                    labels: {
                                        style: {
                                            color: textColor
                                        }
                                    },
                                    splitLine: {
                                        show: true,
                                        lineStyle: {
                                            color: lineColor,
                                            width: 1
                                        }
                                    }
                                },

                                dataZoom: [
                                    {
                                        type: "inside",
                                        start: 0,
                                        end: 10,
                                        height: 15
                                    },
                                    {
                                        start: 0,
                                        end: 20,
                                        borderColor: "#373f51",
                                        textStyle: {
                                            color: textColor,
                                            fontSize: "10"
                                        },
                                        labelFormatter: function(value, time) {
                                            console.log(value, time);
                                            return (
                                                time.split(" ")[0] +
                                                "\n" +
                                                time.split(" ")[1]
                                            );
                                        }
                                    }
                                ],
                                series: [
                                    {
                                        data: historyValue,
                                        type: "line",
                                        animation: false,

                                        // showSymbol :false,
                                        sampling: "average", // 降采样策略-明显优化拖动滚动条卡顿
                                        smooth: false,
                                        lineStyle: {
                                            color: {
                                                type: "linear",
                                                x: 0,
                                                y: 0,
                                                x2: 1,
                                                y2: 0,
                                                colorStops: [
                                                    {
                                                        offset: 1,
                                                        color: "#0174FF" // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 0,
                                                        color: "#2BCC8F" // 100% 处的颜色
                                                    }
                                                ]
                                            }
                                        },
                                        itemStyle: {
                                            color: {
                                                type: "linear",
                                                x: 0,
                                                y: 0,
                                                x2: 1,
                                                y2: 0,
                                                colorStops: [
                                                    {
                                                        offset: 1,
                                                        color: "#0174FF" // 0% 处的颜色
                                                    },
                                                    {
                                                        offset: 0,
                                                        color: "#2BCC8F" // 100% 处的颜色
                                                    }
                                                ]
                                            }
                                        }
                                    }
                                ]
                            });
                        }, 150);
                    } else {
                        this.$message.error(rt.data.message);
                    }
                })
                .catch(err => {
                    console.log("err---", err);
                    this.loadingHistory = false;
                });
        },

        // tabNab切换
        onTabNav(no) {
            this.loading = false;
            this.searchWordLeft = "";
            this.mainSearchCon = "";
            this.rightWord = "";
            this.tabNavType = no;
            this.$refs.pagination.internalCurrentPage = 1;
            this.pageNoRight = 1;
            this.equipYcAndYxAndSet(this.nowEquipStaNo, this.nowEquipNo);

            this.tabNavNumber = no;
            if (no === 1) {
                this.yxShow = false;
                this.equipSetShow = false;
                this.ycShow = true;
                this.tabHeaderSetShow = false;
            } else if (no === 2) {
                this.ycShow = false;
                this.equipSetShow = false;
                this.yxShow = true;
                this.tabHeaderSetShow = false;
                this.curveType.name = '实时';
                this.curveType.func = this.onSplineChartRealTime;
            } else {
                this.ycShow = false;
                this.yxShow = false;
                this.equipSetShow = true;
                this.tabHeaderSetShow = true;
            }
        },

        // 判断状态圆点颜色
        stateJudge(no) {
            let className = "";
            switch (parseInt(no)) {
                case 0:
                    className = "NoCommunication";
                    break;
                case 1:
                    className = "CommunicationOK";
                    break;
                case 2:
                    className = "HaveAlarm";
                    break;
                case 3:
                    className = "HaveSetParm";
                    break;
                case 4:
                    className = "initial";
                    break;
                case 5:
                    className = "CheFang";
                    break;
                case 6:
                    className = "BackUp";
                    break;
                default:
                    className = "CommunicationOK";
                    break;
            }
            return className;
        },

        // 获取当前设备的测点数量
        getStationNumber(equipNo) {
            this.$api.getYcYxSetNumByEquipNo(equipNo).then(rt => {
                if (rt.data.code === 200) {
                    this.stationNumber = rt.data.data;
                }
            });
        },

        // 子菜单点击事件
        getItem(item) {
            if (!item.data.isGroup) {
                const { key, equipState, staNo, title } = item.data;
                this.tabNavType = 1;
                this.tabNavNumber = 1;
                this.pageNoRight = 1;
                this.loading = true;
                this.ycShow = true;
                this.yxShow = false;
                this.tabHeaderSetShow = false;
                this.equipSetShow = false;
                this.searchWordLeft = "";
                this.rightWord = "";
                this.mainSearchCon = "";
                this.$refs.pagination.internalCurrentPage = 1;
                this.tableDataYc = [];

                this.equipConNm = title;
                this.equipYcAndYxNo = key;

                if (this.clearTimeoutVariable) {
                    clearTimeout(this.clearTimeoutVariable);
                }

                try {
                    if (this.signalrConnection) {
                        this.signalrConnection.stop();
                    }
                } catch (e) {
                    console.log(e);
                }
                this.clearTimeoutVariable = setTimeout(() => {
                    if (key) {
                        this.connectHub(key);
                    }
                }, 2000);

                this.nowEquipStaNo = staNo;
                this.nowEquipNo = key;

                // let status = $(`[data-no=${key}]`).attr('class').split(' ');
                this.equipConState = equipState; // 选中设备状态
                this.$store.commit("setSelectedEquip", key); // 选中设备NO
                this.equipYcAndYxAndSet(staNo, key);
                this.equipConMainEquipListDisplayNone = false;

                this.getStationNumber(key);
            }
        },

        toEquipList() {
            this.equipConMainEquipListDisplayNone = true;
        },

        // 父菜单点击事件
        // showToggle (dt) {
        //     if (
        //         $(dt)
        //             .parent()
        //             .hasClass('active')
        //     ) {
        //         $(dt)
        //             .parent()
        //             .removeClass('active');
        //     } else {
        //         $(dt)
        //             .parent()
        //             .addClass('active');
        //     }
        // },

        // 设备发送控制操作命令
        onSetOperate(type, item) {
            let data = {
                equipNo: item.equipNo,
                setNo: item.setNo,
                setType: item.setType,
                value: item.value,
                userName: sessionStorage.getItem("userName")
            };
            if (item.setType !== "V") {
                this.$confirm(
                    item.setNm + this.$t("equipList.set.execute"),
                    this.$t("equipList.set.titleTip"),
                    {
                        confirmButtonText: this.$t("equipList.set.yes"),
                        cancelButtonText: this.$t("equipList.set.cancel"),
                        type: "warning",
                        iconClass: 'iconfont icongw-icon-tishi2'
                    }
                )
                    .then(() => {
                        this.setCommandBySetNo(data);
                    })
                    .catch(() => {});
            } else {
                this.$prompt(this.$t("equipList.set.value"), item.setNm, {
                    confirmButtonText: this.$t("equipList.set.yes"),
                    cancelButtonText: this.$t("equipList.set.cancel")
                })
                    .then(({ value }) => {
                        data.value = value;
                        this.setCommandBySetNo(data);
                    })
                    .catch(() => {});
            }
        },

        setCommandBySetNo(data) {
            this.$api
                .getSetCommandBySetNo(data)
                .then(rt => {
                    if (rt.data.code === 200) {
                        this.$message({
                            message: this.$t("equipList.timeUi.success"),
                            type: "success"
                        });
                    } else {
                        this.$message.error(rt.data.message);
                    }
                })
                .catch(err => {
                    console.log("err---", err);
                });
        },

        // 资产点击事件跳转到资产清单
        goToZiChan(id, name) {
            if (name.length > 0) {
                this.$router.push({
                    path: "/index/assetManagement",
                    query: {
                        id,
                        name
                    }
                });
            }
        },

        // 左侧设备搜索---回车事件
        onSearchSide() {
            this.pageNoLeft = 1;
            this.searchWordLeft = this.searchEquipSideCon.trim();

            this.equipSide();
        },

        onSearchHeaderChange() {
            if (this.mainSearchCon == "") {
                this.onSearchHeader();
                this.onSearchHeaderX();
            }
        },

        // 遥信遥测回车
        onSearchHeader() {
            this.rightWord = this.mainSearchCon.trim();
            this.pageNoRight = 1;
            this.$refs.pagination.internalCurrentPage = 1;
            this.equipYcAndYxAndSet(this.nowEquipStaNo, this.nowEquipNo);
        },
        onSearchHeaderX() {
            if (this.mainSearchCon === "") {
                this.rightWord = "";
                this.pageNoRight = 1;
                this.$refs.pagination.internalCurrentPage = 1;
                this.equipYcAndYxAndSet(this.nowEquipStaNo, this.nowEquipNo);
            }
        },

        // 返回第一个设备OBJ
        returnEquipObject(obj) {
            if (obj.length > 0) {
                for (let i = 0; i < obj.length; i++) {
                    if (obj[i].equipLists.length > 0) {
                        localStorage.first = JSON.stringify(
                            obj[i].equipLists[0]
                        );
                        break;
                    } else if (obj[i].children.length > 0) {
                        this.returnEquipObject(obj[i].children);
                    }
                }
            } else {
                localStorage.first = JSON.stringify([]);
            }
        },

        // 取消定时器
        clearTimer() {
            if (this.getModelValueTime) {
                clearInterval(this.getModelValueTime);
            }
            if (this.timeChart) {
                clearInterval(this.timeChart);
            }
            this.getModelValueTime = "";
            this.timeChart = "";
        },

        // 字符转化DOM连接
        domConversion(str) {
            if (!str) {
                return false;
            }
            str = str.toString().toLowerCase();
            if (
                str.indexOf("ftp") != -1 ||
                str.indexOf("http") != -1 ||
                str.indexOf("https") != -1
            ) {
                return true;
            }
            return false;
        }
    }
};
